﻿using System;
using System.Collections.Generic;
using System.Linq;
using ELearningSystem.Core.Interface;
using ELearningSystem.DAO.DAO;
using ELearningSystem.Gateway.Entities;

namespace ELearningSystem.Core.Manager
{
    public class AnswerManager : IAnswerManager
    {
        public List<AnswerDAO> GetAnswersFromAnswersStringAndCorrectAnswersString(string answresString, string correctString)
        {
            char[] seperator = {'\n'};
            List<string> answerStrings = answresString.Split(seperator,StringSplitOptions.RemoveEmptyEntries).ToList();
            List<int> correct = (correctString.Split(',')).Select(Int32.Parse).ToList();

            var answers = new List<AnswerDAO>();

            foreach (string answerText in answerStrings)
            {
                AnswerDAO answer = new AnswerDAO();
                answer.Text = answerText;
                answers.Add(answer);
            }

            foreach (int i in correct)
            {
                int correctAnswerNumber = i-1; //
                answers[correctAnswerNumber].IsCorrect = true;
            }

            return answers;
        }
    }
}
